package com.example.lib;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyClass {
    public static int player_num = 0;
    public static int player1_score=0;
    public static boolean player1_alive=true;
    public static boolean player2_alive=true;

    public static int player2_score=0;
    public static boolean matched = false;
    public static void main(String[] args){
        new MyClass();
    }

    public MyClass(){
        try {
            // 1. 创建ServerSocket
            ServerSocket serverSocket = new ServerSocket(9999);
            System.out.println("--Listener Port: 9999--");
            while (true) {
                if (player_num == 2) {
                    break;
                }
                //2.等待接收请求，这里接收客户端的请求
                Socket client = serverSocket.accept();
                player_num += 1;
                //3.开启子线程线程处理和客户端的消息传输
                new ServerSocketThread(client, player_num).onStart();
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}